package lab03.test04;

import java.io.*;

public class Test04 {
    public static void main(String[] args) {
        FileInputStream fileInputStream=null;
        FileOutputStream fileOutputStream=null;
        String s="";


//创建文件夹
        File file1=new File("D:\\source");
        file1.mkdir();
        File file2=new File("D:\\target");
          file2.mkdir();


//写入MP3文件
        try {
            fileOutputStream=new FileOutputStream("D:\\source\\High.mp3");
            fileOutputStream.write(new String("sdfsdfsdf").getBytes());
            System.out.println("写入成功");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        //读取MP3文件
        try {
            fileInputStream=new FileInputStream("D:\\source\\High.mp3");
            byte[] b=new byte[fileInputStream.available()];//字节转换成数组
            while (fileInputStream.read(b)!=-1){
        s=new String(b);
            }
            System.out.println("读取成功");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //写入mp3文件到另一个文件中
try {
            fileOutputStream=new FileOutputStream("D:\\target\\High.mp3");
fileOutputStream.write(new String(s).getBytes());
    System.out.println("写入成功");

} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
finally {
    try {
        fileOutputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
    }
}
